/**
 * Created by LeungZ on 2016/8/8.
 */
class Service {
    constructor(serviceSrv, list, ctgNotification, $stateParams) {
        "ngInject";
        this._serviceSrv = serviceSrv;
        this._notification = ctgNotification;
        this.dbCode = $stateParams.kDbCode;

        this.page = {
            currentPage: 1,
            totalItems: 0
        };
        this.filter = {
            name: null,
            namespace: null
        };
        if (list) {
            this.table = list.replicationControllers;
            console.log(list);
            this.page.totalItems = list.replicationControllerNum;
        } else this.table = [];
    }

    getList() {
        this.table = null;
        this._serviceSrv.getRCList({page: this.page.currentPage, code: this.dbCode}, this.filter).then(data=> {
            this.table = data.replicationControllers;
            this.page.totalItems = data.replicationControllerNum;
        }).catch(()=> {
            this.table = [];
            this.page.totalItems = 0;
            this._notification.error('获取服务列表数据有误.');
        });
    }

    search() {
        this.page.currentPage = 1;
        this.getList();
    }
}

export default Service;